package com.chengshuang.log.fuction.task;

import com.chengshuang.log.domain.ProjectTask;
import com.chengshuang.log.fuction.LogRecordSnapshotFunction;
import org.springframework.stereotype.Component;

/**
 * 任务快照
 *
 * @author shuang.cheng
 * @date 2022/10/13
 */
@Component
public class TaskSnapshotFunction implements LogRecordSnapshotFunction {

    private final String FUNCTION_NAME = "task_snapshot";

    @Override
    public String functionName() {
        return FUNCTION_NAME;
    }

    @Override
    public Object snapshotApply(Object value) {
        // 根据任务ID获取任务修改前的信息
        ProjectTask task = new ProjectTask();

        if (value instanceof Long) {
            Long taskId = (Long) value;
            task.setTaskId(taskId);
            task.setTaskType(1);
            task.setTaskName("自定义任务");
            task.setDesc("自定义任务描述");
        } else {
            return null;
        }
        return task;
    }
}
